﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

namespace VentaPorCatalogos.Common
{
    public static class WebControlsEx
    {
        public static int IndexOf(this System.Web.UI.WebControls.DataKeyArray dataKeyArray, object value)
        {
            if (dataKeyArray.Count < 1) throw new InvalidOperationException("DataKeyArray contains no elements.");
            var keys = dataKeyArray.Cast<DataKey>().ToList();
            var key = keys.SingleOrDefault(k => k.Value.Equals(value));
            if (key == null) return -1;
            return keys.IndexOf(key);
        }
    }
}